#include "block.hpp"

void* Consumer(void* argv)
{
  BlockQueue<int>* q = (BlockQueue<int>*) argv;
  while(true){
      int data;
      q->Pop(data);
      printf("###########################\n");
      printf("消费者进行消费：%d\n", data);
      sleep(1);
    }
}

void* Producer(void* argv)
{
  BlockQueue<int> *q = (BlockQueue<int>*) argv;
  while(true){
    int data = rand() % 100 + 1;
    q->Push(data);
    printf("###########################\n");
    printf("生产者进行生产：%d\n", data);
    sleep(1);
  }
}

int main()
{
  srand((unsigned int)(time(nullptr)));
  BlockQueue<int>* q = new BlockQueue<int>();
  //for(int i = 0; i < 5; i++)
  
  pthread_t thd1, thd2;
  pthread_create(&thd1, nullptr, Consumer, (void*)q);
  pthread_create(&thd2, nullptr, Producer, (void*)q);

  pthread_join(thd1, nullptr);
  pthread_join(thd2, nullptr);
  return 0;
}
